<script setup lang="ts">
import { ref, onMounted } from 'vue'
import * as echarts from 'echarts'

const echartsRef = ref()

onMounted(() => {
  let myCharts = echarts.init(echartsRef.value)

  let option = {
  tooltip: {
    trigger: 'item'
  },
  legend: {
    top: 30,
    right: 20,
    orient: 'vertical', // 图例默认方向（垂直）
    textStyle: {
      color: '#fff',
      fontSize: 14
    }
  },
  series: [
    {
      name: 'Access From',
      type: 'pie',
      radius: ['40%', '70%'],
      avoidLabelOverlap: false,
      itemStyle: {
        borderRadius: 10,
        borderColor: '#fff',
        borderWidth: 2
      },
      label: {
        show: true,
        position: 'inside',
        color: '#fff'
      },
      emphasis: {
        label: {
          show: true,
          fontSize: 40,
          fontWeight: 'bold'
        }
      },
      labelLine: {
        show: false
      },
      data: [
        { value: 1048, name: '50以上' },
        { value: 735, name: '40-50' },
        { value: 580, name: '30-40' },
        { value: 484, name: '20-30' },
        { value: 300, name: '20以下' }
      ]
    }
  ]
};

  // 设置实例
  myCharts.setOption(option)
})
</script>

<template>
  <div class="age">
    <div class="top">
      <p class="title">年龄比例</p>
      <p class="bg"></p>
    </div>

    <!-- 图表 -->
    <div class="charts" ref="echartsRef"></div>
  </div>
</template>

<style lang="scss" scoped>
.age {
  width: 100%;
  height: 100%;
  background: url('../../images/dataScreen-main-lb.png') no-repeat;
  background-size: 100% 100%;

  .top {
    margin-left: 20px;
    color: #fff;
    overflow: hidden;
    font-size: 20px;

    .bg {
      width: 68px;
      height: 7px;
      background: url('../../images/dataScreen-title.png') no-repeat;
      background-size: 100%;
      margin-top: 10px;
    }
  }

  .charts {
    height: 200px;
  }
}
</style>